var t, a = getApp(), e = require("../../../utils/util.js");

Page({
    data: {
        evaluate_title: "好评",
        slider: 5,
        content: "",
        noteMaxLen: 140,
        noteNowLen: 0,
        src: "",
        imgArr: [],
        uploadimgArr: [],
        textareaVal: ""
    },
    sliderChange: function(t) {
        var a = "";
        switch (t.detail.value) {
          case 1:
            a = "差评";
            break;

          case 2:
            a = "较差";
            break;

          case 3:
            a = "一般";
            break;

          case 4:
            a = "良好";
            break;

          case 5:
            a = "好评";
            break;

          default:
            a = "差评";
        }
        this.setData({
            slider: t.detail.value,
            evaluate_title: a
        });
    },
    textareaVal: function(t) {
        var a = this, e = t.detail.value, o = parseInt(e.length);
        o > a.data.noteMaxLen || a.setData({
            content: e,
            noteNowLen: o
        });
    },
    addImg: function() {
        var t = this;
        this.data.imgArr, this.data.uploadimgArr;
        wx.chooseImage({
            count: 3,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                var e = a.tempFilePaths;
                t.setData({
                    imgArr: e
                });
            }
        });
    },
    upLoadImge: function(t, e, o) {
        wx.uploadFile({
            url: a.globalData.url + "wx/sys/uploadUrl",
            filePath: t,
            name: "file",
            header: {
                "content-type": "multipart/form-data"
            },
            formData: {
                commentId: e,
                shopId: o
            },
            success: function(t) {
                JSON.parse(t.data.trim()).state || wx.showToast({
                    icon: "fail",
                    title: "上传失败",
                    duration: 2e3
                });
            },
            fail: function() {
                wx.showToast({
                    icon: "fail",
                    title: "上传失败",
                    duration: 2e3
                });
            },
            complete: function() {
                wx.hideToast();
            }
        });
    },
    imgDel: function(t) {
        var a = this.data.imgArr, e = t.target.dataset.index;
        if (a.length) for (var o = 0; o < a.length; o++) o == e && a.splice(o, 1);
        this.setData({
            imgArr: a
        });
    },
    previewImage: function(t) {
        wx.previewImage({
            current: t.target.dataset.url,
            urls: [ t.target.dataset.url ]
        });
    },
    onLoad: function(a) {
        t = this, void 0 !== a.shopId && this.setData({
            shopId: a.shopId,
            orderId: a.orderId
        });
    },
    submit: function() {
        var o = a.globalData.token;
        "" == t.data.content || null == t.data.content ? wx.showToast({
            title: "请输入评价内容",
            icon: "none"
        }) : e.request(a, "wx/cust/evaluate", "GET", {
            token: o,
            evalScore: t.data.slider,
            evalContent: t.data.content,
            orderId: t.data.orderId
        }, function(a) {
            if (a.state) {
                t.setData({
                    commentId: a.data.commentId,
                    shopId: a.data.shopId
                });
                var e = t.data.imgArr;
                if (null != e) for (var o in e) t.upLoadImge(e[o], a.data.commentId, a.data.shopId);
                wx.showToast({
                    title: "评价成功"
                }), setTimeout(function() {
                    wx.switchTab({
                        url: "/pages/home/home"
                    });
                }, 2e3);
            }
        }, function(t) {});
    }
});